import { defineStore } from "pinia";
import { intelConsoleKey } from "../key";
import { MessageConsole, intelmsg, usermsg } from "@/type/console/intelConsole";
interface IBasicState {
    intelConsoleState: MessageConsole;
}
// 定义 Pinia store
export const useIntelStore = defineStore(intelConsoleKey, {
    state(): IBasicState {
        return {
            intelConsoleState: {
                messages: [] as Array<usermsg | intelmsg>
            }

        }
    },
    actions: {
        // 添加消息
        addMessage(msg: usermsg | intelmsg) {
            if (  this.intelConsoleState.messages.length >= 10) {
                // 如果队列已满，移除第一个消息
                this.intelConsoleState.messages.shift();
            }
            // 添加新消息到队列末尾
            this.intelConsoleState.messages.push(msg);
        },
        clearMessage(){
            this.intelConsoleState.messages = []
        }
    },
    getters: {
        // 获取消息列表
        getmessages(state) { return state.intelConsoleState.messages} 
    },
    persist: {
        // 如果需要持久化，可以在这里配置
        pick : ["intelConsoleState"]
    },
});